$(function(){
	
	//alert("here cool!!");
	
	function getLogContent() {
		var maxTime = $('#maxTime').text();
		var timestamp = Date.parse(new Date());
		var eventId = $('#eventId').text();
		//alert(maxTime);
		$.ajax({
			type: "post",
			url: "/ag/lwc/getLogInAnalyse_CurrentPsContentAction.action?ts="+timestamp,
			data: {maxTime:maxTime,eventId:eventId},
			success:showData
		});
	}
	
	/*
	 * 日期转换
	 */
	function stringToDate(date) {
		
		var dateAndTime = date.split("T");
		
		//alert(a);
		
		var newDate = dateAndTime[0]+" "+dateAndTime[1];
		
		//alert(b);
		return newDate;
	}
	
	function showData(data){
		
		if(data.logList != null) {
			$.each(data.logList,function(i,n){
				var newDate = stringToDate(n.logTime);
				//alert(newDate);
				$('#maxTime').text(newDate);
				
				fillIntoHtml(newDate,n.logContent,n.tbLogType.ltName);
				
			});
		}
	}
	/*
	 * 分离用户各和日志内容
	 */
	function getNameAndContent(str){
		var ss = str.split("#@$%");
		return ss;
	}
	
	function fillIntoHtml(date,content,type) {
		var ary = getNameAndContent(content);
		var sHtml = "<tr><td>";
			sHtml += "<p>【"+type+"】<br> "+ary[0]+":&nbsp;&nbsp;"+date+"<br>";
			sHtml += "&nbsp;&nbsp;&nbsp;&nbsp;"+ary[1];
			sHtml += "</td></tr>";
			
		$('#forlog').prepend(sHtml);
		
	}
	getLogContent();
	setInterval(getLogContent,5000);
	
});